package mall

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"newbeemallStudyProject/global"
	"newbeemallStudyProject/model/common/enum"
	"newbeemallStudyProject/model/common/response"
)

type MallIndexApi struct{}

func (m *MallIndexApi) QueryIndex(c *gin.Context) {
	fmt.Println("进入到api层")
	//轮播图查询
	err, carousList := mallCarouselService.GetCarous(5)
	if err != nil {
		global.GVA_LOG.Error("轮播图获取失败"+err.Error(), zap.Error(err))
		response.FailWithMsg(c, "轮播图获取失败")
	}
	fmt.Println(carousList)
	err, hotGoods := mallIndexService.QueryMallIndexConfigInfo(enum.IndexGoodsHot.Code(), 5)
	if err != nil {
		global.GVA_LOG.Error("热销商品获取失败"+err.Error(), zap.Error(err))
		response.FailWithMsg(c, "热销商品获取失败")
	}
	err, newGoods := mallIndexService.QueryMallIndexConfigInfo(enum.IndexGoodsNew.Code(), 5)
	if err != nil {
		global.GVA_LOG.Error("新品获取失败"+err.Error(), zap.Error(err))
		response.FailWithMsg(c, "新品获取失败")
	}
	err, recomGoods := mallIndexService.QueryMallIndexConfigInfo(enum.IndexGoodsRecommond.Code(), 5)
	if err != nil {
		global.GVA_LOG.Error("推荐商品获取失败"+err.Error(), zap.Error(err))
		response.FailWithMsg(c, "推荐商品获取失败")
	}

	indexResult := make(map[string]interface{})
	indexResult["carousels"] = carousList
	indexResult["hotGoodses"] = hotGoods
	indexResult["newGoodses"] = newGoods
	indexResult["recommendGoodses"] = recomGoods
	response.OkWithData(c, indexResult)
}
